/*
 *------------------------------------------------------------------------------
 * @File      :    ei_mai_smart_face.h
 * @Date      :    2021-4-8
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Media Interface for MADP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */

#ifndef __EI_SMART_FACE_H__
#define __EI_SMART_FACE_H__

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

typedef enum {
	CAP_FACE_SUCCESS = 0,
	CAP_ERR_INVALID_FACE_PIXEL,
	CAP_ERR_INVALID_FACE_YAW,
	CAP_ERR_INVALID_FACE_PITCH,
	CAP_ERR_INVALID_FACE_ROLL,
	CAP_ERR_INVALID_FACE_CLARITY,
	CAP_ERR_INVALID_FACE_CLARITY_MASK,
	CAP_ERR_INVALID_FACE_OCCLUSION,
} EI_MADP_SMART_FACE_CAP_ERR_CODE_E;

typedef struct eiMADP_SMART_FACEDET_RESULT_S {
	EI_S32 s32Rect[4];
	EI_FLOAT f32Kpts[10];
	EI_FLOAT f32Score;

	EI_U64 u64Timestamp;
} EI_MADP_SMART_FACEDET_RESULT_S;

/** the attribute of smart facedet*/
typedef struct eiMADP_SMART_FACEDET_RESULTS_S {
	EI_U32 s32Num;
	EI_MADP_SMART_FACEDET_RESULT_S stFaces[DEFAULT_NNA_FACE_DET_CONFIG_MAX_DET_CNT];
	EI_U32 u32FrameWidth;
	EI_U32 u32FrameHeight;
	EI_U32 NnHandle;
	EI_NNA_FACES_S stNnaDetResult;
} EI_MADP_SMART_FACEDET_RESULTS_S;

typedef EI_S32 (*EI_MADP_SMART_FaceDet_DataCB) (EI_HANDLE hFaceDet, EI_MADP_SMART_FRAME_S *pstSmartFrame,
	EI_MADP_SMART_FACEDET_RESULTS_S *pstFaceDetResults, EI_VOID *pPrivData);

/** the attribute of smart facedet*/
typedef struct eiMADP_SMART_FACEDET_ATTR_S {

	EI_U32 u32FrameWidth;
	EI_U32 u32FrameHeight;
	EI_S32 s32FrameType;

	EI_S32 s32MaxDetSize;
	EI_S32 s32MinDetSize;
	EI_S32 s32MaxDetFaces;
	EI_S32 s32Roi[4];

	EI_MADP_SMART_FaceDet_DataCB pfnDataCB;
	EI_VOID *pPrivateData;
} EI_MADP_SMART_FACEDET_ATTR_S;

typedef struct eiMADP_SMART_FACETRK_RESULT_S {
	// trk
	EI_U32 u32Id;
	// det
	EI_S32 s32Rect[4];
	EI_FLOAT f32Kpts[10];
	EI_FLOAT f32Score;

	// attribute
	EI_FLOAT f32Yaw;
	EI_FLOAT f32Pitch;
	EI_FLOAT f32Roll;
	EI_S32 s32ClarityScore;
	EI_NNA_FACE_CLARITY_LEVEL_E eClarityLevel;

	//mask
	EI_S32 s32Mask;

	//face occlusion
	EI_FLOAT f32FaceOccScore;
	EI_FLOAT f32GlassesProbability;
	EI_FLOAT f32MaskProbability;

	//face attr
	EI_NNA_FACE_ATTR_S stFaceAttr;

	//cap flag
	EI_MADP_SMART_FACE_CAP_ERR_CODE_E err_code;

	EI_U64 u64Timestamp;
} EI_MADP_SMART_FACETRK_RESULT_S;

/** the result of smart facetrk*/
typedef struct eiMADP_SMART_FACETRK_RESULTS_S {
	EI_U32 s32Num;
	EI_MADP_SMART_FACETRK_RESULT_S stFaces[DEFAULT_NNA_FACE_TRK_CONFIG_MAX_TRACK_FACE];
	EI_U32 NnHandle;
	EI_NNA_FACES_S stNnaTrkResult;
} EI_MADP_SMART_FACETRK_RESULTS_S;

typedef EI_S32 (*EI_MADP_SMART_FaceTrk_DataCB) (EI_HANDLE hFaceTrk, EI_MADP_SMART_FRAME_S *pstSmartFrame,
	EI_MADP_SMART_FACETRK_RESULTS_S *pstFaceTrkResults, EI_VOID *pPrivData);

/** the attribute of smart facetrk*/
typedef struct eiMADP_SMART_FACETRK_ATTR_S {
	EI_HANDLE hFaceDet;
	EI_U32 u32FrameWidth;
	EI_U32 u32FrameHeight;
	EI_U32 s32MaxTrackFaces;

	EI_MADP_SMART_FaceTrk_DataCB pfnDataCB;
	EI_VOID *pPrivateData;
	void *reserved;
} EI_MADP_SMART_FACETRK_ATTR_S;

typedef struct eiMADP_SMART_FACESNAP_VENC_DATA_S {
	EI_VOID *pVStreamData;
	EI_U32 s32FrameId;
	EI_BOOL bRecg; //AlreadySendToRecgQueue flag
	EI_U8 *pu8Addr;
	EI_U32 au32Len;
} EI_MADP_SMART_FACESNAP_VENC_DATA_S;

typedef struct eiMADP_SMART_FACESNAP_resultS_S {
	EI_S32 s32FaceId;

	// det
	EI_S32 s32Rect[4];
	EI_FLOAT f32Kpts[10];
	EI_FLOAT f32Score;

	// attribute
	EI_FLOAT f32Yaw;
	EI_FLOAT f32Pitch;
	EI_FLOAT f32Roll;
	EI_S32 s32ClarityScore;

	//face attr
	EI_NNA_FACE_ATTR_S stFaceAttr;

	//mask
	EI_S32 s32Mask;

	//face occlusion
	EI_FLOAT f32FaceOccScore;

	EI_S32 s32FrameId;
	EI_MADP_SMART_FACESNAP_VENC_DATA_S *pstFaceVencData;
	EI_MADP_SMART_FACESNAP_VENC_DATA_S *pstBgVencData;

	EI_U64 u64Timestamp;
} EI_MADP_SMART_FACESNAP_RESULTS_S;

typedef EI_S32 (*EI_MADP_SMART_FaceCap_SnapDataCB)(EI_HANDLE hFaceCap,
	EI_MADP_SMART_FACESNAP_RESULTS_S *pstSmartFaceSnapResults, EI_VOID *pPrivData);

/** the attribute of smart facecap*/
typedef struct eiMADP_SMART_FACECAP_S {
	/* init attr start*/
	EI_HANDLE Vproc;
	EI_HANDLE Vport;
	EI_HANDLE VencChn;
	EI_HANDLE VdecChn;
	EI_HANDLE FaceCap;
	EI_HANDLE FaceDet;
	EI_HANDLE FaceTrk;
	EI_HANDLE FaceRecg;

	/*0: default use internal get frame*/
	/*1: using external frame (interface: EI_MAI_Smart_Face_FrameCb or MAI_Smart_Face_SendFrame) */
	EI_S32 s32UsingExternalFrame;

	EI_U32 u32FrameWidth;
	EI_U32 u32FrameHeight;
	/* init attr end */

	/* face det */
	EI_S32 s32FaceDetModle; /* 0: facedet 1:humfacedet */
	EI_S32 s32MaxDetPx;
	EI_S32 s32MinDetPx;
	EI_S32 s32MaxDetCnt;
	EI_S32 s32DetRoi[4];
	EI_MADP_SMART_FaceDet_DataCB pfnDetDataCB;
	EI_VOID *pPrivateDetData;

	/* face trk */
	EI_S32 s32EnFaceTrk; /*0: disable nna trk; 1: enable nna trk */
	EI_S32 s32UseFakeTrk; /* when s32EnFaceTrk == 0; */
						  /*0:  disable fake trk ; 1: enable max area fake trk */
	EI_MADP_SMART_FaceTrk_DataCB pfnTrkDataCB;
	EI_VOID *pPrivateTrkData;

	/* conf switch */
	EI_S32 EnCapDumpImage;
	EI_S32 s32CapFaceMode; /*EI_MADP_SMART_FACE_CAP_MODE_E*/
	EI_S32 s32CapFaceInterval;
	EI_S32 s32CapFaceJpegQuality;
	EI_S32 s32DumpBgImage;
	EI_S32 s32CapMinFacePx;
	EI_S32 s32CapMaxFacePx;
	EI_MADP_SMART_FaceCap_SnapDataCB pfnCapDataCB;
	EI_VOID *pPrivateCapData;

	/* Face exposure */
	EI_S32 s32FaceExposure; /* 0: disable 1: biggest face mode 2: mulit faces mode*/

	/* Face mask det */
	EI_S32 s32EnFaceMaskDet;

	/* Face mask clarity det */
	EI_S32 s32EnFaceMaskClarityDet;
	EI_S32 s32CapMinClarityMask;
	EI_S32 s32CapMaxClarityMask;

	/* Face occlusion det */
	EI_S32 s32EnFaceOccDet;
	EI_S32 s32FaceOccThresh;

	/* Face attr det */
	EI_S32 s32EnFaceAttrDet;

	/* Face pose det */
	EI_S32 s32EnFacePoseDet;
	EI_FLOAT f32CapMinPitch;
	EI_FLOAT f32CapMinYaw;
	EI_FLOAT f32CapMinRoll;
	EI_FLOAT f32CapMaxPitch;
	EI_FLOAT f32CapMaxYaw;
	EI_FLOAT f32CapMaxRoll;

	/* Face clarity det */
	EI_S32 s32EnFaceClarityDet;
	EI_S32 s32CapMinClarity;
	EI_S32 s32CapMaxClarity;

	/* Face recg */
	EI_S32 s32FaceRecgEnable;
	EI_S32 s32FaceRecgMode; /*mode EI_MADP_SMART_FACE_RECOGIZE_MODE_E */
	EI_S32 s32FaceRecgJpegMode; /* 0: bg image 1: small image */

	/*facerecg_or_imagestore_queue_cache_size*/
	EI_U32 u32FaceRecgQueueCacheSize;

} EI_MADP_SMART_FACECAP_ATTR_S;

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif /* __EI_SMART_FACE_H__ */

